﻿#ifndef TABLELINEEDIT_H
#define TABLELINEEDIT_H

#include <QLineEdit>
#include <QCompleter>
#include <QMimeData>
#include <QKeyEvent>
#include <functional>

using QStringCallback_fn = std::function<QString(const QString&)>;


class TableLineEdit : public QLineEdit
{
    Q_OBJECT
public:
    explicit TableLineEdit(QWidget *parent = nullptr);
    explicit TableLineEdit(const QString& text, QWidget *parent = nullptr);

    void setAutoComplete(const QStringList &displays, const QStringList &values);
    void enableAutoComplete(bool en);

    enum Direction {
        Left, Top, Right, Bottom
    };

    void setPasteCallback(QStringCallback_fn callack);

signals:
    void focusMoveRequest(Direction direction);
    void keyEnterRequest();

protected:
    void init();

protected:
    void focusInEvent(QFocusEvent *e) override;
    bool focusNextPrevChild(bool) override;
    void mousePressEvent(QMouseEvent *e) override;
    void keyPressEvent(QKeyEvent *e) override;

private:
    QCompleter* m_completer;
    bool m_enAC;
    QStringCallback_fn m_callback = nullptr;
};

#endif // TABLELINEEDIT_H
